package com.corner.presenter.imp;

import com.corner.model.cornerservice.domain.Info;
import com.corner.model.cornerservice.domain.Like;
import com.corner.model.cornerservice.helper.InfoHelper;
import com.corner.presenter.IIntersetionPresenter;
import com.corner.presenter.base.BasePresenter;
import com.corner.ui.view.IItersectionView;

import java.util.List;

import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;

/**
 * Created by Administrator on 2015/7/15，16.17.
 * 描述：
 */
public class IntersectionPresenter extends BasePresenter<IItersectionView> implements IIntersetionPresenter {
    @Override
    public void requestReadedUsers(Info info) {
        InfoHelper.getReadedUsers(info).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<List<Like>>() {
            @Override
            public void call(List<Like> likes) {
                if (view != null)
                    view.showReadedUsers(likes);
            }
        }, new Action1<Throwable>() {
            @Override
            public void call(Throwable throwable) {
                if (view != null)
                    view.showRequestError(throwable.getMessage());
            }
        });

    }

    @Override
    public void requestAgreeUsers(Info info) {
        InfoHelper.getLikeUsers(info).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<List<Like>>() {
            @Override
            public void call(List<Like> likes) {
                if (view != null)
                    view.showAgreeUsers(likes);
            }
        }, new Action1<Throwable>() {
            @Override
            public void call(Throwable throwable) {
                if (view != null)
                    view.showRequestError(throwable.getMessage());
            }
        });
    }


}
